package net.maku.system.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.mybatis.service.impl.BaseServiceImpl;
import net.maku.system.convert.SysUserChargeConvert;
import net.maku.system.entity.SysUserChargeEntity;
import net.maku.system.query.SysUserChargeQuery;
import net.maku.system.vo.SysUserChargeVO;
import net.maku.system.dao.SysUserChargeDao;
import net.maku.system.service.SysUserChargeService;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 充值记录
 *
 * @author 小陈 
 * @since 1.0.0 2025-03-19
 */
@Service
@AllArgsConstructor
public class SysUserChargeServiceImpl extends BaseServiceImpl<SysUserChargeDao, SysUserChargeEntity> implements SysUserChargeService {

    @Override
    public PageResult<SysUserChargeVO> page(SysUserChargeQuery query) {
        IPage<SysUserChargeEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));

        return new PageResult<>(SysUserChargeConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }

    private LambdaQueryWrapper<SysUserChargeEntity> getWrapper(SysUserChargeQuery query){
        LambdaQueryWrapper<SysUserChargeEntity> wrapper = Wrappers.lambdaQuery();
        return wrapper;
    }

    @Override
    public void save(SysUserChargeVO vo) {
        SysUserChargeEntity entity = SysUserChargeConvert.INSTANCE.convert(vo);

        baseMapper.insert(entity);
    }

    @Override
    public void update(SysUserChargeVO vo) {
        SysUserChargeEntity entity = SysUserChargeConvert.INSTANCE.convert(vo);

        updateById(entity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {
        removeByIds(idList);
    }

}